package top.superflow.verify

import java.io.File

import shapeless.TypeCase
import top.superflow.exception.RequestUnsupportedException

trait FileEnsure extends Ensure{
  
  def shouldExist(file : Any) : Boolean = {
    notNull(file, "File should not be null")
    
    val stringList = TypeCase[List[String]]
    val fileList = TypeCase[List[File]]
    
    file match {
      case filePath : String => {
        notEmpty(filePath, "File path should not empty!")
        shouldExist(new File(filePath))
      }
      case file : File => {
        if(!file.exists()){
          throw new RequestUnsupportedException("The file or folder:" + file.getAbsoluteFile + " does not exist!")
        }
        true
      }
      
      case stringList(sl) => {
        for(filePath <- sl){
          shouldExist(filePath)
        }
      }
      
      case fileList(fl) => {
        for(file <- fl){
          shouldExist(file)
        }
      }
    }
    
    true
  }
  
}